# 操作图
from graphlib import TopologicalSorter

graph = {'D': {"B", "C"}, "C": {"A"}, "B": {"A"}}
ts = TopologicalSorter(graph)
print(tuple(ts.static_order()))  # ('A', 'C', 'B', 'D')
ts = TopologicalSorter()
ts.add(3, 2, 1)
ts.add(1, 0)
print([*ts.static_order()])  # [2, 0, 1, 3]
